<!--
 * @Descripttion:
 * @Author: Silence
 * @Date: 2023-08-12 11:42:19
 * @LastEditors: Silence
 * @LastEditTime: 2023-08-12 11:42:31
-->
<template>
  <!-- 设备管理 -->
  <div class="div-one">
    <div class="header">
      <el-form :inline="true" :model="dataList" class="demo-form-inline">
        <el-form-item label="设备编号:">
          <el-input v-model="dataList.innerCode" placeholder="请输入">
            <i slot="suffix" class="el-icon-error" @click="empty" />
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            class="cha"
            @click="getOperateData"
          >查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="body">
      <div class="body-btn">
        <el-button
          type="warning"
          class="xin"
          icon="el-icon-circle-plus-outline"
          @click="addListData"
        >
          新建
        </el-button>
        <el-button type="warning" plain class="gong" @click="batchList">批量操作</el-button>
      </div>

      <el-table
        ref="multipleTable"
        :data="deviveList"
        tooltip-effect="dark"
        style="width: 100%"
        @select="onSelect"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column label="序号" prop="nodeId" width="100" />
        <el-table-column prop="innerCode" label="设备编号" width="245" />
        <el-table-column
          prop="name"
          label="设备型号"
          width="245"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <span>{{ row.region.name }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="ownerName"
          label="合作商"
          width="245"
          show-overflow-tooltip
        />
        <el-table-column
          prop="vmStatus"
          label="设备状态"
          width="245"
          show-overflow-tooltip
        >
          <template #default="{ row }">
            <span>{{ row.vmStatus ? row.vmStatus === 1 ? '运营':'撤机':'未投放' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" show-overflow-tooltip>
          <template #default>
            <el-button type="text">货道</el-button>
            <el-button type="text">策略</el-button>
            <el-button type="text">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 添加弹窗 -->
      <el-dialog
        title="新增设备"
        :visible.sync="dialogVisible"
        width="40%"
        :before-close="handleClose"
      >
        <el-form ref="form" :model="form" :rules="rules" label-width="150px">
          <el-form-item label="设备编号:">
            <span>系统自动生成</span>
          </el-form-item>
          <el-form-item label="选择型号:" prop="vmType">
            <el-select v-model="form.name" placeholder="请选择" size="medium" style="width:400px">
              <el-option v-for="item in shouhuoji" :key="item.id" :label="item.name" :value="item.name" />
            </el-select>
          </el-form-item>
          <el-form-item label="选择地点:" prop="nodeId">
            <el-select v-model="form.region.remark" placeholder="请选择" size="medium" style="width:400px">
              <el-option v-for="item in point" :key="item.id" :label="item.name" :value="item.name" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-row>
              <el-button style="margin-left:50px" @click="handleClose">取消</el-button>
              <el-button type="warning" style="margin-left:40px" @click="submit">确认</el-button>
            </el-row>
          </el-form-item>
        </el-form>
      </el-dialog>
      <!-- 弹窗 -->
      <CelueguanLi ref="celueguanLi" />
    </div>
  </div>
</template>
<script>
import { loginList, dianWeiList, shouHuojiList, addDataList } from '../../api/devive'
import CelueguanLi from './compponents/celuegaunli.vue'

export default {
  name: '',
  components: {
    CelueguanLi
  },
  data() {
    return {
      dataList: {
        pageIndex: 1,
        pageSize: 10,
        status: null,
        innerCode: null
      },
      deviveList: [],
      dialogVisible: false,
      form: {
        region: '',
        name: '',
        createUserId: null
      },
      rules: {
        nodeId: [
          { required: true, message: '请选择地点', trigger: 'blur' }
        ],
        vmType: [
          { required: true, message: '请选择型号', trigger: 'blur' }
        ]
      },
      selected: [],
      shouhuoji: [],
      selected: []
    }
  },
  computed: {
  },
  created() {
    this.getOperateData()
  },
  methods: {
    // 获取数据
    async getOperateData() {
      const data = await loginList(this.dataList)
      console.log(data, 1212)
      this.deviveList = data.data.currentPageRecords
    },
    // TODO
    handleSelectionChange() {},
    // 查询
    async  queryLList() {
      this.getOperateData()
    },
    // 情空input框内容
    empty() {
      this.dataList.innerCode = ''
      this.getOperateData()
    },
    // 添加设备弹窗
    async addListData() {
      const data = await dianWeiList()
      console.log(data, 777)
      this.point = data.data.currentPageRecords

      const res = await shouHuojiList()
      console.log(res, 6666)
      this.shouhuoji = res.data.currentPageRecords
      this.dialogVisible = true
    },
    // 关闭弹窗
    handleClose() {
      this.$refs.form.resetFields()
      this.dialogVisible = false
    },
    // 提交添加售货机
    async submit() {
      try {
        this.$refs.form.validate()
        const data = await addDataList(this.form)
        console.log(data)
      } catch (error) {
        console.log(error)
      }
    },
    onSelect(rows) {
      // console.log(rows)
      this.selected = rows
    },
    // 批量操作
    batchList() {
      // console.log(this.selected)
      if (this.selected.length) {
        // console.log(1)
        this.$refs.celueguanLi.dialogShbetVisible = true
        this.$refs.celueguanLi.strategy()
      } else {
        this.$message.warning('请勾选售货机')
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.el-drawer_header span:focus {
  outline: 0;
}
.div-one {
  background-color: #f8fafd;
  padding: 20px;
  .header {
    width: 100%;
    background-color: #fff;
    padding: 20px 0 0 20px;
    height: 80px;
    margin-bottom: 20px;
    .cha {
      background-color: #5f84ff;
    }
  }
  .body {
    background-color: #fff;
    padding: 20px 0 0 20px;
    .body-btn {
      margin-bottom: 20px;
      .xin {
        background-color: #ff6725;
      }
      .gong {
        background-color: #fbf4f0;
        color: #000;
      }
    }
    .el-table-column {
      height: 50px;
    }
  }
}
</style>
